import baseapi from '@/api/base'
import { getDataByParameter, getObjetInfoByPid, getCountByParameter, saveObjetInfo, deleteObjetInfo,getDownload ,postInfo} from '@/utils/baserequest'
import storage from 'store'

const Base64 = require('js-base64').Base64

const api = {
  appContext: baseapi.biz,
  appAppId: baseapi.biz_app,
  appServer: 'purchaseMedicalProductInfo',//caiGouMuLu
  appServer2: 'purchaseMedicalProductInfo',
  //商品库列表
  getStoreByConditions: 'dataAreaUse/by/findLikeExample',
  getStoreByConditionsCount: 'dataAreaUse/countLikeExample/',
  //v1.0医院端供应商商品列表 caiGouMuLu 
  getByConditions: 'purchaseMedicalProductInfo/by/supplier/findMoreLikeExample',
  getByConditionsCount: 'purchaseMedicalProductInfo/countMoreLikeExample/supplier/',
  //审核caiGouMuLu
  auditInfo:'purchaseMedicalProductInfo/review',


  //下载标准商品数据
  downloadData:'purchaseMedicalProductInfo/downfile/supplier/findMoreLikeExample',
  //v2.0医院端、供应商端商品列表
  getByAreaUse: 'purchaseMedicalProductInfo/by/findLikeExample',
  getByAreaUseCount: 'purchaseMedicalProductInfo/countLikeExample/',   
  //推送商品
  pushGoods:'purchaseMedicalProductInfo/multilineToSupplier',
  //已推送商品列表
  getPushedGoods: 'purchaseMedicalProductInfo/by/supplierMePur/findLikeExample',
  getPushedGoodsCount: 'purchaseMedicalProductInfo/countBy/supplierMePur/findMoreLikeExample', 
  //推送  原接口：keHuXiaoShouChanPin
  pushInfo:'purchaseMedicalProductInfo/pushNew/',
  //推送2(推送) {"pids":"all"||"pid1,pid2,...","state": "待审核"}
  pushInfo2:'purchaseMedicalProductInfo/changeState',
  
  
}
export default api
//根据商品数据域代码请求商品
export function getPushedGoods(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getPushedGoods
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//根据商品数据域代码请求商品
export function getPushedGoodsCount(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getPushedGoodsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//根据商品数据域代码请求商品
export function getByAreaUse(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getByAreaUse
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//根据商品数据域代码请求商品
export function getByAreaUseCount(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getByAreaUseCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//多条件查询商品包
export function getStoreByConditions(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getStoreByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数商品包
export function getStoreByConditionsCount(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getStoreByConditionsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}

//多条件查询
export function getByConditions(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数
export function getByConditionsCount(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getByConditionsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}

//下载商品包
export function downloadData(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
  }
  const url = api.appContext + api.downloadData
  const allheaders = appIdHeaders
  return getDownload(url, pa, allheaders)
  
}
//新增和修改
export function saveInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/'
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}
//新增和修改
export function saveInfos(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer2 + '/'
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}
//删除
export function deleteInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer2 + '/'
  const allheaders = appIdHeaders
  return deleteObjetInfo(url, parameter, allheaders)
}
// 通过pid得到信息通用请求:get请求
export function getInfoByPid(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer
  const allheaders = appIdHeaders
  return getObjetInfoByPid(url, parameter, allheaders)
}

// 审核
export function auditInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.auditInfo
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}

// 推送
export function pushInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.pushInfo
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}

// 推送2
// {
//   "pids":"all"||"pid1,pid2,...",
//   "state": "待审核"
// }
export function pushInfo2(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.pushInfo2
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}
export function pushGoods(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.pushGoods
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}
//上传厂家证照
export function saveSellerLicense(parameter) { 
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer2 + '/' 
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}

// 通过pid得到厂家证照
export function getLicenseByPid(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer2
  const allheaders = appIdHeaders
  return getObjetInfoByPid(url, parameter, allheaders)
}






